#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x7f7f7f7f
int col[33000][20],c[20],a[20],T,n;
void paint(int x){
    if(x == n + 1) return;
    int pow2 = 1;
    for(int i = x;i < n;i++) pow2 *= 2;
    for(int i = 1;i <= pow2;i++){
        col[i][x] = 1;
    }
    paint(x + 1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while(T--){
        cin >> n;
        if(n <= 15){
            paint(1);
            for(int i = 1;i <= n;i++){
                cin >> a[i];
            }
            int pown = pow(2,n);
            int ans = -1;
            for(int i = 1;i <= pown;i++){
                for(int j = 1;j <= n;j++) c[j] = 0;
                for(int j = 1;j <= n;j++){
                    for(int k = j - 1;k >= 1;k--){
                        if(col[i][k] == col[i][j] && a[j] == a[k]){
                            c[j] = a[j];
                        }
                    }
                }
                int sum = 0;
                for(int j = 1;j <= n;j++) sum += c[j];
                ans = max(ans,sum);
            }
            cout << ans << "\n";
        }
    }
    return 0;
}
